package main

import (
	"context"
	"os"
	"path/filepath"

	"github.com/google/uuid"
	"golang.design/x/clipboard"
)

type RuntimeExt struct {
	ctx context.Context
}

func NewRuntimeExt() *RuntimeExt {
	return &RuntimeExt{}
}

func (runtime *RuntimeExt) startup(ctx context.Context) {
	runtime.ctx = ctx
}

func (runtime *RuntimeExt) ClipImage() (uri string, err error) {
	err = clipboard.Init()
	if err != nil {
		return
	}

	b := clipboard.Read(clipboard.FmtImage)
	uri = uuid.NewString() + ".png"
	file, err := os.Create(filepath.Join(GetAbsPath(globalConfig.AttachmentPath), uri))
	if err != nil {
		return
	}

	_, err = file.Write(b)
	return
}
